<?php
namespace Home\Controller;
use Common\Controller\HomebaseController;
class LeavemsgController extends HomebaseController 
{   
    protected $leavemsgObj;
	public function _initialize()
	{
        parent::_initialize();
        $this->leavemsgObj = D("Leavemsg");
	}

	public function index()
	{
    	$this->lists();
	}

	public function lists()
	{
      $count      =  $this->leavemsgObj->count();
      $Page       = new \Think\Page($count,15);
      $show       = $Page->show();
      $where['status']=$this->status;
      $list = $this->leavemsgObj->where($where)->order(array("status" => "ASC","id" => "ASC"))->limit($Page->firstRow.','.$Page->listRows)->select();
      $this->assign('list',$list);
      $this->assign('page',$show); 
      $this->display('list');
	}
  public function save()
  {
      $nickname = I('post.inputNickname','0','htmlspecialchars');
      $email = I('post.inputEmail','','htmlspecialchars');
      $msg = I('post.inputMsg','','htmlspecialchars');
      $data = array();
      $data['nickname']=$nickname;
      $data['email']  = $email;
      $data['title'] = 'null';
      $data['msg'] = $msg;
      $data['status'] = 0;
      $data['createtime'] = time();
      $addResult =  $this->leavemsgObj->add($data);
      if($addResult) {
          $arr = array("status"=>'1',"message"=>"提交在线留言成功","url"=>"");
      }else{
          $arr = array("status"=>'0',"message"=>"提交在线留言失败");
      }
      echo json_encode($arr);
  }
}
?>